<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/20
  Time: 20:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link href="static/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<br>
<br>
<div class="container">
    <div class="page-heading">
        汽车美容系统
        <button>
            欢迎会员${sessionUser.realname}
            (会员号:${sessionUser.no} 电话号码:${sessionUser.phone})
            当前余额:<span id="money">${sessionUser.money}</span>
        </button>
    </div>
    <div>
        <table class="table table-bordered">
            <tr>
                <th>编号</th>
                <th>消费类型</th>
                <th>描述</th>
                <th>价格</th>
                <th>操作</th>
            </tr>

            <c:forEach items="${list}" var="s">
            <tr>
                <td>${s.id}</td>
                <td>${s.name}</td>
                <td>${s.desc}</td>
                <td>${s.price}</td>
                <td>
                    <button class="btn btn-primary" id="btn-submit" type="button" price=${s.price}>消费</button>
                </td>
            </tr>
            </c:forEach>
        </table>
    </div>
</div>

<script src="static/js/jquery.js"></script>
<script src="static/plugin/layer/layer.js"></script>

<script>
    $('#btn-submit').click(function () {
        $.ajax({
            url:'consume_list',
            type:'get',
            data:{

                price:$(this).attr('${s.price}')
            },
            dataType:"json",
            success:function (r) {
                if(r==0){
                    var toMoney=Number($('#money').text());
                    var price=Number($(this).attr('${s.price}'));
                    $('#money').text('已消费').prop("disabled",true);
                }else{
                    layer.alert(r.msg);
                }
            }
        })
    })
</script>
</body>
</html>
